package com.widget.benson.strip;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.widget.benson.strip.widget.ObservableScrollView;
import com.widget.benson.strip.widget.ObservableScrollViewCallbacks;
import com.widget.benson.strip.widget.ScrollState;
import com.widget.benson.strip.widget.ScrollUtils;


public class MainActivity extends ActionBarActivity  implements ObservableScrollViewCallbacks {
    private ObservableScrollView mScrollView;
    private View strip;
    private float stripY;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mScrollView= (ObservableScrollView) findViewById(R.id.scroll);

        mScrollView.setScrollViewCallbacks(this);
        strip=findViewById(R.id.strip);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
       float transitiony= ScrollUtils.getFloat(-scrollY, -stripY, 0);
        strip.setTranslationY(transitiony);
    }

    @Override
    public void onDownMotionEvent() {

    }

    @Override
    public void onUpOrCancelMotionEvent(ScrollState scrollState) {

    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        if(hasFocus){
            if(stripY==0){
                stripY=strip.getY();
            }
        }


        super.onWindowFocusChanged(hasFocus);
    }
}
